#include <iostream>
using namespace std;
#include <vector>

void binsearch(vector<int>& v1)
{
  int left = 0;
  int right = v1.size() -1;
  // left 
  if (v1[1] > v1[0])
  {
    cout << "find the min num:" << v1[left] << "index:" << left << endl;
    return;
  }
  // right 
  if (v1[right -1 ] > v1[right])
  {
    cout << "find the min num:" << v1[right] << "index:" << right << endl;
    return;
  }

  while(left <= right)
  {
    int mid = (left + right) / 2;
    if (v1[mid] < v1[mid - 1])
    {
      if (v1[mid] < v1[mid + 1])
      {
        cout << "find the min num:" << v1[mid] << "  index:  " << mid << endl;
        return;
      }
      else 
      {
        left = mid + 1;
      }
    }
    else 
    {
      right = mid - 1;
    }
  }
}



int main()
{
  vector<int> v1 = {3 , 1, 5, 6, 7, 5, 7, 8, 1, 9};
  binsearch(v1);
  return 0;
}
